import { ControlZoom } from './../types/Control';
import { Directive, Input, OnDestroy, OnInit } from '@angular/core';

/*
import {
  toGeolocationOptions,
  toMapTypeControlOptions,
  toNavigationControlOptions,
  toOverviewMapControlOptions,
  toScaleControlOptions
} from '../helpers/transformer'
*/

import { nullCheck } from '../helpers/validate';
import { MapService } from '../providers/mapService';
import { Control , ControlOptions } from '../types/Control';
import { TMapInstance } from '../types/Map';

@Directive({
  selector: 'tdt-control'
})
export class ControlDirective implements OnInit, OnDestroy {
  @Input() private type: string;
  @Input() private options: ControlOptions;

  private control: Control;

  constructor(private _service: MapService) {

  }

  public ngOnInit() {
      console.log(this.type);
    nullCheck(this.type, 'type is required for <control>');

    this.control = this.createControl(this.type, this.options);

    this._service.addControl(this.control);
  }

  public ngOnDestroy() {
    this._service.removeControl(this.control);
  }

  private createControl(
    type: string,
    options: { [key: string]: any }
  ): Control | null {

    if (type === 'zoom') {
      return new window.T.Control.Zoom(this.options);
    }

    throw new Error(`Unsupported type:${type} of control`);
  }
}
